﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Xml;
using TomanuExtensions;
using TomanuExtensions.Utils;

namespace AmiEmuLib.AmigaConfiguration.DisplayConfig
{
    /// <summary>
    /// Fullscreen display configuration.
    /// </summary>
    public class Fullscreen : XmlBase
    {
        /// <summary>
        /// For compatibility with WinUAE its not same as screen resolution.
        /// </summary>
        public Size Resolution = new Size(); 

        /// <summary>
        /// Scale factor.
        /// </summary>
        public ScaleFactor ScaleFactor;

        /// <summary>
        /// Scaling mode. Scale amiga display by ScaleFactor or fit amiga display in host display.
        /// </summary>
        public FullscreenScalingMode Scaling;

        /// <summary>
        /// Try to cut overscan borders.
        /// </summary>
        public bool IgnoreBorders;

        /// <summary>
        /// VSync mode.
        /// </summary>
        public VSyncMode VSync;

        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="a_reader"></param>
        public Fullscreen(XmlReader a_reader)
            : base(a_reader)
        {
        }

        protected override void ReadXml(XmlReader a_reader)
        {
            a_reader.ReadStartElement(GetType().Name);

            Resolution = a_reader.ReadElementContentAsSize("Resolution");
            ScaleFactor = a_reader.ReadElementContentAsEnum<ScaleFactor>("ScaleFactor");
            Scaling = a_reader.ReadElementContentAsEnum<FullscreenScalingMode>("Scaling");
            IgnoreBorders = a_reader.ReadElementContentAsBoolean("IgnoreBorders");
            VSync = a_reader.ReadElementContentAsEnum<VSyncMode>("VSync");

            a_reader.ReadEndElement();
        }

        public override void WriteXml(XmlWriter a_writer)
        {
            a_writer.WriteStartElement(GetType().Name);

            a_writer.WriteElementSize("Resolution", Resolution);
            a_writer.WriteElement<ScaleFactor>("ScaleFactor", ScaleFactor);
            a_writer.WriteElement<FullscreenScalingMode>("Scaling", Scaling);
            a_writer.WriteElement("IgnoreBorders", IgnoreBorders);
            a_writer.WriteElement<VSyncMode>("VSync", VSync);
            
            a_writer.WriteEndElement();
        }
    }
}
